<template>
    <div class="page-bottom-bar">
        <div class="flex-item tip-message">预估报价：<span>￥</span><span>{{price}}</span>
            <span class="open" v-if="isbaozhi==1">（已开启价格保护)</span>
        </div>
<!--        <div class="flex-item open"><span>（已开启价格保护)</span></div>-->
        <div class="flex-item">
            <span v-if="changeButtom!='change'" @click="eventClickconfirmOrder" class="bar-button bar-button-green">确认收取</span>
            <span v-else  @click="eventClickChangeOrder" class="bar-button bar-button-green">确认更改</span>
        </div>
    </div>
</template>

<style lang="scss" scoped>
    @import "../../../libs/styles/bottom-fixed-bar.scss";

    .tip-message {
        padding-left: 1rem;
        text-align: left;

        span {
            color: #FF0000;
        }

        span:first-child {
            font-size: 1.3rem;
        }

        span:last-child {
            font-size: 1.9rem;
        }
        .open{
            font-size: 1rem !important;
            color: #FF9000  !important;
        }
    }

</style>

<script>
    import { Switch } from 'vant';

    export default {
        name: "bottom-submit-confirm-collect",
        props:['price','isbaozhi','ordernumber','changeButtom','detail','dataset'],
        components: {
            [Switch.name]: Switch
        },
        data() {
            return {
            }
        },
        methods:{
            eventClickconfirmOrder(){
                // console.log(this.$route.query);
                var url = '/api/home/order/confirm',
                    param = {
                        ordernumber:this.ordernumber,
                        token:this.$store.state.options.user.token
                    };

                if(this.$route.query.mode == 'zg') {
                    url = '/api/home/order/change';
                    param = {
                        type: 'shenheoutorder',
                        token:this.$store.state.options.user.token,
                        id: this.ordernumber
                    };
                }

                this.$util.postRequestInterface(url,param,(res)=>{
                    this.$router.go(-1)
                })
            },
            buildFormaDataset(mode) {
                var result = [];
                for(let x of this.detail) {
                    result.push({
                        garbageid:x.garbagepgalist,
                        id: x.id,
                        weighting_num: x.number,
                        // weighting_method: x.weight ? 0 : 1,
                        danweiming:x.danweiming
                    });
                }
                return result;
            },
            eventClickChangeOrder(){
                console.log(this.buildFormaDataset());
                var url = '/api/home/order/adjust';
                var param = {
                    ordernumber:this.ordernumber,
                    token:this.$store.state.options.user.token,
                    garbagelist:JSON.stringify(this.buildFormaDataset()),
                    paytype:this.dataset.paytype?1:0,
                    delivery_method:this.dataset.delivery_method?1:0
                };
                this.$util.postRequestInterface(url,param,(res)=>{
                    this.$router.go(-1)
                })
            }
        }
    }
</script>
